<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GET IP</title>
</head>
<body>
<div id="dom"></div>
</body>
</html>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
    // 下面这行和上面的script一起使用  获取真实IP地址
    document.write(returnCitySN["cip"]+','+returnCitySN["cname"] + "真实IP地址")
    // 下面的一堆 单独使用 获取本地的IP地址
    function findIP(callback) {
        var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; //compatibility for firefox and chrome
        var pc = new myPeerConnection({iceServers: []}),
                noop = function() {},
                localIPs = {},
                ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
                key;

        function ipIterate(ip) {
            if (!localIPs[ip]) callback(ip);
            localIPs[ip] = true;
        }
        pc.createDataChannel("");
        pc.createOffer().then(function(sdp) {
            sdp.sdp.split('\n').forEach(function(line) {
                if (line.indexOf('candidate') < 0) return;
                line.match(ipRegex).forEach(ipIterate);
            });
            pc.setLocalDescription(sdp, noop, noop);
        });
        pc.onicecandidate = function(ice) {
            if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
            ice.candidate.candidate.match(ipRegex).forEach(ipIterate);
        };
    }

    findIP(function(ip){
        let dom = document.getElementById('dom')
        dom.innerHTML = ip + "你的本地IP地址"
    });
</script>

>